﻿using System;
using System.Collections.Generic;
using KZ.Utilities;
using System.Data;
namespace KZ.Express.H.ENT
{
    public class OrderENT : BaseENT
    {
        [Output]
        public int OrderID { get; set; }

        [Required(ErrorMessage = "Bạn phải nhập số bill")]
        public string OrderNumber { get; set; }

        public int? CreatedBy { get; set; }

        [NotInsertUpdate]
        public DateTime? CreatedDate { get; set; }

        public int? UpdatedBy { get; set; }

        [NotInsertUpdate]
        public DateTime? UpdatedDate { get; set; }

        [NotInsertUpdate]
        public override int IsRecovery { get; set; }

        [NotInsertUpdate]
        public override string Table { get { return "Orders"; } }

        [NotInsertUpdate]
        public override string PrimaryKey { get { return "OrderID"; } }

        [NotInsertUpdate]
        public override string PrimaryDescription { get { return "OrderNumber"; } }

        [NotInsertUpdate]
        public override string InsertProcedure { get { return "proc_Order_Insert"; } }

        [NotInsertUpdate]
        public override string UpdateProcedure { get { return "proc_Order_Update"; } }

        [NotInsertUpdate]
        public override string SelectProcedure { get { return "proc_Order_Select"; } }

        public readonly static string UpdateFuelProcedure = "proc_Order_Update_Fuel";

        public readonly static string UpdateStandardPriceProcedure = "proc_Order_Update_StandardPrice";

        public readonly static string SelectExportProcedure = "proc_Order_Select_Export";

        public readonly static string SelectStatisticalProcedure = "proc_Order_Select_Statistical";

        public static void CalculateBillCount(DataTable dt, out int billCount, out int doxCount, out int packCount)
        {
            billCount = doxCount = packCount = 0;
            foreach (DataRow row in dt.Rows)
            {
                if (Utility.IntParse(row["OrderID"]) > 0)
                {
                    billCount++;
                    if (Utility.StringParse(row["Type"]) == "DOX")
                        doxCount++;
                    else
                        packCount++;
                }
            }
        }

        public static void CalculateBillCount(DataTable dt, out int billCount, out int doxCount, out int packCount,
            out decimal totalRate, out decimal commission)
        {
            billCount = doxCount = packCount = 0;
            totalRate = commission = 0;
            foreach (DataRow row in dt.Rows)
            {
                if (Utility.IntParse(row["OrderID"]) > 0)
                {
                    billCount++;
                    if (Utility.StringParse(row["Type"]) == "DOX")
                        doxCount++;
                    else
                        packCount++;

                    totalRate += Utility.DecimalParse(row["TotalRate"]);
                    commission += Utility.DecimalParse(row["Commission"]);
                }
            }
        }

        public static void CalculateBillCount(DataTable dt, out int billCount, out int doxCount, out int packCount,
            out decimal totalRate, out decimal commission, out decimal handlingfee, out decimal carrier, out decimal standardPrice, out decimal profit)
        {
            billCount = doxCount = packCount = 0;
            totalRate = commission = handlingfee = carrier = standardPrice = profit = 0;
            foreach (DataRow row in dt.Rows)
            {
                if (Utility.IntParse(row["OrderID"]) > 0)
                {
                    billCount++;
                    if (Utility.StringParse(row["Type"]) == "DOX")
                        doxCount++;
                    else
                        packCount++;

                    totalRate += Utility.DecimalParse(row["TotalRate"]);
                    commission += Utility.DecimalParse(row["Commission"]);
                    handlingfee += Utility.DecimalParse(row["HandlingFee"]);
                    carrier += Utility.DecimalParse(row["Carrier"]);
                    standardPrice += Utility.DecimalParse(row["StandardPrice"]);
                    profit += Utility.DecimalParse(row["Profit"]);
                }
            }
        }
    }
}